"""
    1:内置函数
    2:拆包/解构
    3:异常
"""
from functools import reduce

"""
   内置函数 一般情况
   1：大写开头：内置变量名
   2：小写开发：内置函数名
   3：__XXX__: 特殊方法，一般自调用 
   abs() 返回值 
   sum([可迭代对象]) 
   min():最小值  
   max():最大值 
   len():长度 
   zip():将可迭代对象打包成一个元组, 必须是可迭代对象
   map():映射/转换 函数
   reduce()
   print():输出
"""
import builtins
print(dir(builtins))
print(min(1, 2, 3))
print(max(-1, -2, -3, key= abs)) # >>> -3
print(max([1, 2, 3]))
print(zip(["a", "b", "c"], [1, 2, 3])) # >>> <zip object at 0x00000211016A6A00>
print(zip(["a", "b", "c"], "1")) # >>> TypeError: 'int' object is not iterable
print(list(zip(["a", "b", "c"], [1, 2, 3]))) # >>> [('a', 1), ('b', 2), ('c', 3)]
print(list(map(lambda x: 2*x, [1, 2, 3]))) # >>> [2, 4, 6]
print(list(map(abs, [-1, -2, -3]))) # >>> [1, 2, 3]
print(reduce(lambda x, y: x+y, [1, 2, 3])) # >>> 6
print(reduce(lambda x, y: x+y, ["a", "b", "c"])) # >>> abc

"""
    拆包/解构  
"""
tup = (1, 2, 3)
a, b, c = tup
print(f"a = {a}, b = {b}, c = {c}") # >>> a = 1, b = 2, c = 3
a, *b = tup
cls = type(b)
print(f"a = {a}, b ={cls} {b}") # >>> a = 1, b =<class 'list'> [2, 3]
c, d = b
print(f"c = {c}, d = {d}") # >>> c = 2, d = 3


"""
    异常
"""
try:
    print(bb)
except:
    print("执行报错")

try:
    print(bb)
except Exception:
    print("执行报错")

try:
    print(bb)
except Exception as e:
    print("执行报错", e)
finally:
    print("执行完成")

bb = "abc"
try:
    print(bb)
except NameError as e:
    print("NameError", e)
except IndexError as e:
    print("IndexError", e)
except Exception as e:
    print("Exception", e)
else:
    print("no exception")
finally:
    print("执行完成")

def func91():
    print("func91")
    raise Exception("some exception")
func91()